<template>
  <div>
    <f-form :modal="user" :rules="rules" ref="loginForm">
      <f-form-item label="用户名" prop="uname">
        <f-input v-model="user.uname"></f-input>
      </f-form-item>
      <f-form-item label="密码" prop="pwd">
        <f-input type="password" v-model="user.pwd"></f-input>
      </f-form-item>
      <f-form-item>
        <button @click="login">登陆</button>
      </f-form-item>
    </f-form>
  </div>
</template>

<script>
import FInput from "./form/FInput.vue";
import FFormItem from "./form/FForm-Item.vue";
import FForm from "./form/FForm.vue";

import create from "./utils/modal";
import Notice from "./modal/Notice.vue";

export default {
  components: {
    FInput,
    FFormItem,
    FForm
  },
  data() {
    return {
      user: {
        uname: "test",
        pwd: ""
      },
      rules: {
        uname: [{ required: true, message: "请输入用户名" }],
        pwd: [{ required: true, message: "请输入密码" }]
      }
    };
  },
  methods: {
    login() {
      //验证表单
      this.$refs.loginForm.validate(valid => {
        const notice = create(Notice, {
          title: "醉哥学Vue",
          message: valid ? "请求登录!" : "校验失败!"
        });
        notice.show()
      });
    }
  }
};
</script>

<style lang="scss" scoped>
</style>